
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:keyboard_avoider/keyboard_avoider.dart';

/*
* 类似 预警提示 有输入文本框的提醒框
*
*/
typedef onCloseEvent = void Function();
typedef onPositivePressEvent = void Function(String content);
class PublicWarmInputToast extends Dialog {

  onCloseEvent closeCallBack;
  onPositivePressEvent positiveCallBack;
  String warmTip;
  String title;
  String agreetText;
  String cancelText;
  // final ValueChanged<String> chooseCallback;
  PublicWarmInputToast({
    // @required this.chooseCallback,
    this.agreetText,
    this.cancelText,
    this.title,
    this.warmTip,
    @required this.positiveCallBack,
    @required this.closeCallBack,
  });
  TextEditingController _contentController = new TextEditingController();
  FocusNode _contentFocusNode = FocusNode();
  Widget MainComponent(){
    return Stack(
      children: [
        Opacity(
          opacity: 0.46,
          child:Container(
            color: Color(0xff101010),
            width: ScreenUtil.screenWidth,
            height: ScreenUtil.screenHeight,
          ) ,
        ),
        Positioned(
            top: ScreenUtil().setWidth(250),
            left: ScreenUtil().setWidth(503),
            child: CenterWidget()
        ),
      ],
    );
  }
  //中间视图背景
  Widget CenterBG(){
    return Container(
      decoration: ShapeDecoration(
        color: Color(0xffffffff),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(11.2),
          ),
        ),
      ),
      width:ScreenUtil().setWidth(624) ,
      height: ScreenUtil().setWidth(411.2),
    );
  }
  Widget inputWidget(){
    return Container(
      height:ScreenUtil().setWidth(87),
      width: ScreenUtil().setWidth(545),
      child: TextField(
        focusNode: _contentFocusNode,
        controller: _contentController,
        autofocus: false,
        // keyboardType: TextInputType.multiline,
        decoration: InputDecoration(
          fillColor: Color(0xffF5F5F5),
          filled: true,
          border:OutlineInputBorder(borderSide: BorderSide.none),
          hintText: '请输入审批意见',
        ),

        style: TextStyle(fontFamily: "PingFangSC-Regular", color: Colors.black,fontSize: ScreenUtil().setSp(24),height: 1.1),textAlign: TextAlign.left,
        //文本内容改变时回调
        onChanged: (text) {
          print('文本内容改变时回调 $text');
          _contentController.text = text;
        },
        //内容提交时回调
        onSubmitted: (text) {
          print('内容提交时回调 $text');
        },
      ),
    );
  }

  //中间视图
  Widget CenterWidget(){
    return Stack(
        children: <Widget>[
          CenterBG(),
          Positioned(
            left: ScreenUtil().setWidth(0),
            top: ScreenUtil().setWidth(0),
            child: Container(
              width: ScreenUtil().setWidth(624),
              height: ScreenUtil().setWidth(77.6),
              decoration: ShapeDecoration(
                color: Color(0xffF6F5F7),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(11.2),
                    topRight: Radius.circular(11.2),
                  ),
                ),
              ),
              child:Row(
                children: [
                  SizedBox(width:ScreenUtil().setWidth(42.4),height: ScreenUtil().setWidth(20),),
                  Text(title??"", style: TextStyle(color: Color(0xff000000), fontFamily: 'PingFangSC-Medium',fontSize:ScreenUtil().setSp(26)),textAlign: TextAlign.center,),
                ],
              ),
            ),
          ),
          Positioned(
            left: ScreenUtil().setWidth(16.8),
            top: ScreenUtil().setWidth(278.4),
            child: Container(
              width: ScreenUtil().setWidth(592),
              height: ScreenUtil().setWidth(2),
              color: Color(0xffE4E3E3),
            ),
          ),
          Positioned(
            child: Container(
              width: ScreenUtil().setWidth(624),
              height: ScreenUtil().setWidth(200.8),
              child:Column(
                children: [
                  SizedBox(width:20,height: ScreenUtil().setWidth(25.4),),
                  Text(warmTip??"",style: TextStyle( color: Color(0xff454545),fontFamily: 'PingFangSC-Regular;',fontSize: ScreenUtil().setSp(26)),textAlign: TextAlign.center,maxLines: 3,overflow: TextOverflow.ellipsis,),
                  SizedBox(width:20,height: ScreenUtil().setWidth(10),),
                  inputWidget()
                ],
              ),
            ),
            top: ScreenUtil().setWidth(77.6),
            left: ScreenUtil().setWidth(0),
          ),
          Positioned(
            child: InkWell(
              onTap: (){
                this.closeCallBack();
              },
              child: Container(
                width: ScreenUtil().setWidth(191.6),
                height: ScreenUtil().setWidth(59.1),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30),
                    color:Color(0xffFFFFFF),
                    border: Border.all(
                        color: Color(0xffA2A1A3),
                        width: 1.5,
                        style: BorderStyle.solid
                    )
                ),
                child:new Center(
                  child: new Text(cancelText??"取消",style: TextStyle(fontSize: ScreenUtil().setSp(24),color: Color(0xff0A0A0B)),textAlign: TextAlign.center),
                ),
              ),
            ),
            left: ScreenUtil().setWidth(95),
            top: ScreenUtil().setWidth(310),
          ),
          Positioned(
            child: InkWell(
                onTap:(){
                  this.positiveCallBack(_contentController.text);
                },
                child: Container(
                  width: ScreenUtil().setWidth(191.6),
                  height: ScreenUtil().setWidth(59.1),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30),
                    color:Color(0xffF22A02),
                  ),
                  child: new Center(
                    child:new Text(agreetText??"确定",style: TextStyle(fontSize: ScreenUtil().setSp(24),color: Color(0xffFFFFFF)),textAlign: TextAlign.center,),
                  ),
                )
            ),
            left: ScreenUtil().setWidth(306),
            top: ScreenUtil().setWidth(310),
          ),
        ]
    );
  }
  final ScrollController _scrollController = ScrollController();
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 1600, height: 900, allowFontScaling: true);
    return new Material(
        type: MaterialType.transparency,
        child:Container(
          width:ScreenUtil().setWidth(624) ,
          height: ScreenUtil().setWidth(411.2),
          child: KeyboardAvoider(
            autoScroll: true,
            child: ListView(
              controller: _scrollController,
              children: [
                new Center(
                  child: CenterWidget(),
                )
              ],
            ),
          ),
        )

    );
  }
}
